
// export function delay() {
//   let timer = 0
//   return function(callback, ms) {
//     clearTimeout(timer)
//     timer = setTimeout(callback, ms)
//   }
// }

import {isEmptyString} from "@/utils/protocol";

export function formatMMSS(value) {
  let seconds = value % 60;
  let mins = ((value - seconds)) / 60;
  if (seconds < 10) {
    seconds = "0" + seconds;
  }
  if (mins === 0) {
    return "00:" + seconds;
  } else {
    if (mins < 10) {
      mins = "0" + mins;
    }
    return mins + ":" + seconds;
  }
}

export function isEmptyObject(value) {
  return value === null || value === undefined;
}

export function isEmptyStr(value) {
  return value === null || value === undefined || value === "";
}

export function delay(delayTime) {
  let currentTime = new Date().getTime();
  let flag = true;
  while (flag) {
    if(new Date().getTime() - currentTime > delayTime) {
      flag = false;
    }
  }
}

export const spiderConvertJSON =  {
  "90": "L0(可选)",
  "80": "1",
  "81": "10",
  "82": "100",
  "83": "0.1",
  "84": "0.2",
  "85": "0.3",
  "86": "0.4",
  "50": "TA",
  "51": "TB",
  "52": "TC",
  "53": "TD",
  "54": "TE",
  "55": "TF",
  "200": "KU-1030",
  "91": "R1",
  "92": "R2",
  "93": "R3",
  "94": "R4",
  "95": "R5",
  "96": "R6",
  "97": "R7",
  "98": "R8",
  "99": "R9",
}

export function spindleFormatter(value) {

  let spiderStr = "" + value;
  if(!isEmptyString(spiderConvertJSON[spiderStr])) {
    spiderStr = spiderConvertJSON[spiderStr];
  }
  return spiderStr;
  
}

export function isSpeedSelective(val) {
  return val === 'DV79A' || val === 'DV79B';
}

export function getSpeedOptions(val) {
  if (val === 'DV79A' || val === 'DV79B') {
    return [
        {
          "label": "7.5",
          "value":"7.5"
        },
        {
          "label": "75",
          "value":"75"
        },
        {
          "label": "750",
          "value":"750"
        }];
  }
  return [];
}

export function arrayContains(array, value) {
  if (isEmptyObject(array)) {
    return false;
  }
  for (const arrayElement of array) {
    if (arrayElement.toUpperCase() === value.toUpperCase()) {
      return true;
    }
  }
  return false;
}
